﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using Maticsoft.DBUtility;//Please add references
namespace ORSIMS.DAL
{
	/// <summary>
	/// 数据访问类:USER_INFO
	/// </summary>
	public partial class USER_INFO
	{
		public USER_INFO()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ORSIMS.Model.USER_INFO model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into USER_INFO(");
			strSql.Append("ID,USERID,REALNAME,PASSWORD,DEPT,PRIVLEVEL,PHONE,E_MAIL,REMARK)");
			strSql.Append(" values (");
			strSql.Append(":ID,:USERID,:REALNAME,:PASSWORD,:DEPT,:PRIVLEVEL,:PHONE,:E_MAIL,:REMARK)");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,8),
					new OracleParameter(":USERID", OracleType.VarChar,20),
					new OracleParameter(":REALNAME", OracleType.VarChar,20),
					new OracleParameter(":PASSWORD", OracleType.VarChar,20),
					new OracleParameter(":DEPT", OracleType.VarChar,4),
					new OracleParameter(":PRIVLEVEL", OracleType.VarChar,3),
					new OracleParameter(":PHONE", OracleType.VarChar,20),
					new OracleParameter(":E_MAIL", OracleType.VarChar,50),
					new OracleParameter(":REMARK", OracleType.VarChar,200)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.USERID;
			parameters[2].Value = model.REALNAME;
			parameters[3].Value = model.PASSWORD;
			parameters[4].Value = model.DEPT;
			parameters[5].Value = model.PRIVLEVEL;
			parameters[6].Value = model.PHONE;
			parameters[7].Value = model.E_MAIL;
			parameters[8].Value = model.REMARK;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ORSIMS.Model.USER_INFO model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update USER_INFO set ");
			strSql.Append("ID=:ID,");
			strSql.Append("USERID=:USERID,");
			strSql.Append("REALNAME=:REALNAME,");
			strSql.Append("PASSWORD=:PASSWORD,");
			strSql.Append("DEPT=:DEPT,");
			strSql.Append("PRIVLEVEL=:PRIVLEVEL,");
			strSql.Append("PHONE=:PHONE,");
			strSql.Append("E_MAIL=:E_MAIL,");
			strSql.Append("REMARK=:REMARK");
			strSql.Append(" where ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,8),
					new OracleParameter(":USERID", OracleType.VarChar,20),
					new OracleParameter(":REALNAME", OracleType.VarChar,20),
					new OracleParameter(":PASSWORD", OracleType.VarChar,20),
					new OracleParameter(":DEPT", OracleType.VarChar,4),
					new OracleParameter(":PRIVLEVEL", OracleType.VarChar,3),
					new OracleParameter(":PHONE", OracleType.VarChar,20),
					new OracleParameter(":E_MAIL", OracleType.VarChar,50),
					new OracleParameter(":REMARK", OracleType.VarChar,200)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.USERID;
			parameters[2].Value = model.REALNAME;
			parameters[3].Value = model.PASSWORD;
			parameters[4].Value = model.DEPT;
			parameters[5].Value = model.PRIVLEVEL;
			parameters[6].Value = model.PHONE;
			parameters[7].Value = model.E_MAIL;
			parameters[8].Value = model.REMARK;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from USER_INFO ");
			strSql.Append(" where ");
			OracleParameter[] parameters = {
			};

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ORSIMS.Model.USER_INFO GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,USERID,REALNAME,PASSWORD,DEPT,PRIVLEVEL,PHONE,E_MAIL,REMARK from USER_INFO ");
			strSql.Append(" where ");
			OracleParameter[] parameters = {
			};

			ORSIMS.Model.USER_INFO model=new ORSIMS.Model.USER_INFO();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ORSIMS.Model.USER_INFO DataRowToModel(DataRow row)
		{
			ORSIMS.Model.USER_INFO model=new ORSIMS.Model.USER_INFO();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=decimal.Parse(row["ID"].ToString());
				}
				if(row["USERID"]!=null)
				{
					model.USERID=row["USERID"].ToString();
				}
				if(row["REALNAME"]!=null)
				{
					model.REALNAME=row["REALNAME"].ToString();
				}
				if(row["PASSWORD"]!=null)
				{
					model.PASSWORD=row["PASSWORD"].ToString();
				}
				if(row["DEPT"]!=null)
				{
					model.DEPT=row["DEPT"].ToString();
				}
				if(row["PRIVLEVEL"]!=null)
				{
					model.PRIVLEVEL=row["PRIVLEVEL"].ToString();
				}
				if(row["PHONE"]!=null)
				{
					model.PHONE=row["PHONE"].ToString();
				}
				if(row["E_MAIL"]!=null)
				{
					model.E_MAIL=row["E_MAIL"].ToString();
				}
				if(row["REMARK"]!=null)
				{
					model.REMARK=row["REMARK"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,USERID,REALNAME,PASSWORD,DEPT,PRIVLEVEL,PHONE,E_MAIL,REMARK ");
			strSql.Append(" FROM USER_INFO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM USER_INFO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T. desc");
			}
			strSql.Append(")AS Row, T.*  from USER_INFO T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "USER_INFO";
			parameters[1].Value = "";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

